<template>
  <el-form :model="state.loginForm">
    <el-form-item label="名称">
      <el-input v-model="state.loginForm.name"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input v-model="state.loginForm.password"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button @click="onClick">登陆</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts">
import { defineComponent, getCurrentInstance, reactive } from 'vue'
import { ElForm, ElFormItem, ElInput, ElButton, ElMessage } from 'element-plus'
import { useLoginForm } from '@/effects/useLoginForm'
export default defineComponent({
  name: 'login-form',
  components: {
    ElForm,
    ElFormItem,
    ElInput,
    ElButton
  },
  data() {
    return {
      labelPosition: 'right'
    }
  },
  setup(props, context) {
    // 在setup中，如何获取data中的数据，然后使用
    // const datab = getCurrentInstance()
    const state = reactive({
      loginForm: {
        name: '',
        password: ''
      }
    })
    // 自定义hooks=> 提取公共逻辑
    const { onLoginClick } = useLoginForm()
    const onClick = () => {
      onLoginClick({})
    }

    return {
      state,
      onClick
    }
  }
})
</script>
